/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import Security.EncryptorAES;
import dao.AccountDao;
import pojo.Account;

/**
 *
 * @author Kenneth Veenstra <kenneth.veenstra@gmail.com>
 */
public class AccountManager
{
    private AccountDao accountDao;

    public AccountManager(AccountDao accountDao)
    {
        this.accountDao = accountDao;
    }

    public boolean login(String name, String password)
    {
        System.out.println(name + ", " +  password);
        Account namedAccount = accountDao.getAccountByName(name);
        if ( namedAccount != null )
        {
            return namedAccount.getPassword().equals(EncryptorAES.encrypt(password));
        }
        return false;
    }

    public boolean createAccount(Account account)
    {
        return accountDao.addAccount(account);
    }

    public boolean updateAccount(Account account)
    {
        return accountDao.updateAccount(account);
    }

    public Account getAccount(String name)
    {
        return accountDao.getAccountByName(name);
    }
}
